package com.tangbuzhi.bridge;

/**
 * 桥接模式（桥梁模式）举例：制作咖啡 => 大（小）杯加糖（原味）咖啡
 */
public class BridgeCase {
    public interface CoffeAdd {
        String addSomething();
    }

    public static class Sugar implements CoffeAdd {
        @Override
        public String addSomething() {
            return "加糖";
        }
    }

    public static class Ordinary implements CoffeAdd {
        @Override
        public String addSomething() {
            return "原味";
        }
    }

    public static abstract class Coffe {
        protected CoffeAdd coffeAdd;

        public Coffe(CoffeAdd coffeAdd) {
            this.coffeAdd = coffeAdd;
        }

        public abstract void makeCoffe();
    }

    public static class LargeCoffe extends Coffe {
        public LargeCoffe(CoffeAdd coffeAdd) {
            super(coffeAdd);
        }

        @Override
        public void makeCoffe() {
            System.out.println("大杯的" + coffeAdd.addSomething() + "咖啡");
        }
    }

    public static class SmallCoffe extends Coffe {
        public SmallCoffe(CoffeAdd coffeAdd) {
            super(coffeAdd);
        }

        @Override
        public void makeCoffe() {
            System.out.println("小杯的" + coffeAdd.addSomething() + "咖啡");
        }
    }

    public static void main(String[] args) {
        Sugar sugar = new Sugar();
        Ordinary ordinary = new Ordinary();

        LargeCoffe largeSugerCoffe = new LargeCoffe(sugar);
        largeSugerCoffe.makeCoffe();//大杯的加糖咖啡

        LargeCoffe largeOrdinaryCoffe = new LargeCoffe(ordinary);
        largeOrdinaryCoffe.makeCoffe();//大杯的原味咖啡

        SmallCoffe smallSugarCoffe = new SmallCoffe(sugar);
        smallSugarCoffe.makeCoffe();//小杯的加糖咖啡

        SmallCoffe smallOrdinaryCoffe = new SmallCoffe(ordinary);
        smallOrdinaryCoffe.makeCoffe();//小杯的原味咖啡
    }

    public static class MiddleCoffe extends Coffe {
        public MiddleCoffe(CoffeAdd coffeAdd) {
            super(coffeAdd);
        }

        @Override
        public void makeCoffe() {
            System.out.println("中杯的" + coffeAdd.addSomething() + "咖啡");
        }
    }

    public static class Milk implements CoffeAdd {
        @Override
        public String addSomething() {
            return "加奶";
        }
    }
}
